#include "BlockMgr.h"

BlockMgr::BlockMgr() :m_pBlockPool(nullptr)
{

}

BlockMgr::~BlockMgr()
{

}

bool BlockMgr::Init()
{
	m_pBlockPool = new ObjectPool<Block>(20, false);
	MMO_ASSERT(m_pBlockPool);
	return true;
}

void BlockMgr::UnInit()
{
	MMO_DELETE(m_pBlockPool);
}

IBlock *BlockMgr::MakeBlockObj()
{
	if (nullptr != m_pBlockPool)
	{
		return m_pBlockPool->MallocObj();
	}
	return nullptr;
}

void BlockMgr::FreeBlockObj(IBlock *pBlock)
{
	if (nullptr != pBlock)
	{
		m_pBlockPool->FreeObj((Block*)pBlock);
	}
}

bool BlockMgr::RecycleBlock(IBlock *pBlock)
{
	if (nullptr != pBlock)
	{
		pBlock->uninit();
		FreeBlockObj(pBlock);
	}

	return true;
}
